package com.ruoyi.web.controller.qiushi.mall;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.qiushi.domain.mall.TradeServiceOrder;
import com.ruoyi.qiushi.service.mall.ITradeServiceOrderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务商品订单Controller
 *
 * @author ruoyi
 * @date 2023-12-27
 */
@RestController
@RequestMapping("/qiushi/mall/tradeserviceorder")
public class TradeServiceOrderController extends BaseController {
    @Autowired
    private ITradeServiceOrderService tradeServiceOrderService;

    /**
     * 查询服务商品订单列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradeserviceorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(TradeServiceOrder tradeServiceOrder) {
        startPage();
        List<TradeServiceOrder> list = tradeServiceOrderService.selectTradeServiceOrderList(tradeServiceOrder);
        return getDataTable(list);
    }

    /**
     * 导出服务商品订单列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradeserviceorder:export')")
    @Log(title = "服务商品订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TradeServiceOrder tradeServiceOrder) {
        List<TradeServiceOrder> list = tradeServiceOrderService.selectTradeServiceOrderList(tradeServiceOrder);
        ExcelUtil<TradeServiceOrder> util = new ExcelUtil<TradeServiceOrder>(TradeServiceOrder.class);
        util.exportExcel(response, list, "服务商品订单数据");
    }

    /**
     * 获取服务商品订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradeserviceorder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tradeServiceOrderService.selectTradeServiceOrderById(id));
    }

    /**
     * 新增服务商品订单
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradeserviceorder:add')")
    @Log(title = "服务商品订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TradeServiceOrder tradeServiceOrder) {
        tradeServiceOrder.setUpdateTime(new Date());
        return toAjax(tradeServiceOrderService.insertTradeServiceOrder(tradeServiceOrder));
    }

    /**
     * 修改服务商品订单
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradeserviceorder:edit')")
    @Log(title = "服务商品订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TradeServiceOrder tradeServiceOrder) {
        return toAjax(tradeServiceOrderService.updateTradeServiceOrder(tradeServiceOrder));
    }

    /**
     * 删除服务商品订单
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradeserviceorder:remove')")
    @Log(title = "服务商品订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        TradeServiceOrder tradeServiceOrder = new TradeServiceOrder();
        tradeServiceOrder.setUpdateTime(new Date());
        tradeServiceOrder.setDelFlag("1");
        tradeServiceOrder.setId(id);
        return toAjax(tradeServiceOrderService.updateTradeServiceOrder(tradeServiceOrder));
    }
}
